<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数字滚动效果(0-100)</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        margin: 0;
        background-color: #f0f0f0;
      }

      #countdown {
        font-size: 50px;
        font-weight: bold;
        color: #333;
        padding: 20px;
        background-color: #fff;
        border-radius: 10px;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
      }

      .number {
        display: inline-block;
        font-size: 50px;
        line-height: 60px;
        text-align: center;
        vertical-align: middle;
        margin: 0 5px;
      }

      /* 滚动动画 */
      .roll {
        animation: rollAnimation 1s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
      }

      @keyframes rollAnimation {
        0% {
          transform: translateY(0);
        }
        100% {
          transform: translateY(-100%);
        }
      }
    </style>
  </head>
  <body>
    <div id="countdown">
      <div id="number" class="number">0</div>
    </div>

    <script>
      // 设置初始值和目标值
      const startValue = 0
      const endValue = 100
      const countdownDuration = 500 // 倒计时总时长（10秒）

      // 获取数字显示的容器
      const numberElement = document.getElementById('number')

      // 动态更新数字
      function animateNumber(start, end, duration) {
        const stepTime = duration / end // 每次更新的时间间隔
        let currentValue = start
        const interval = setInterval(() => {
          if (currentValue < end) {
            currentValue++
            numberElement.textContent = currentValue
          } else {
            clearInterval(interval) // 停止计时器
          }
        }, stepTime)
      }

      // 启动数字滚动动画
      animateNumber(startValue, endValue, countdownDuration)
    </script>
  </body>
</html>
